package cc.facesign.admin.utils;

import cc.facesign.admin.bean.EmailBean;
import cc.facesign.admin.bean.mq.SignMq;
import cc.facesign.admin.service.TblUserService;
import cc.facesign.common.utils.bean.MqMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class MqUtils {

    public static final String EXCHANGE_DIRECT = "facesign.direct"; // direct 交换器
    public static final String SING_ROUTER = "conf.sign"; // 会议签到路由键
    public static final String MAP_ROUTER_AND_QUEUE = "map";

    public static final String EMAIL_ROUTER_QUEUE = "email";

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private TblUserService userService;

    /**
     * 发送签到信息
     */
    public void sendForSign(SignMq mq) {
        rabbitTemplate.convertAndSend(EXCHANGE_DIRECT, SING_ROUTER, mq);
    }

    public void sendMap(Map<String, Object> map) {

        MqMessage mes = new MqMessage();
        mes.setData(map);
        rabbitTemplate.convertAndSend(EXCHANGE_DIRECT, MAP_ROUTER_AND_QUEUE, mes);
    }

    public void sendMail(EmailBean emailBean) {

        rabbitTemplate.convertAndSend(EXCHANGE_DIRECT, EMAIL_ROUTER_QUEUE, emailBean);
    }

}
